﻿using Restful_Api.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace Restful_Api.ValidationAttributes
{
    /// <summary>
    /// 自定义验证特性
    /// </summary>
    public class EmployeeAddDtoFirstNameAttribute : ValidationAttribute
    {
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            //获得加上验证的类 或者属性的值         
            var addDto = (EmployeeAddorUpdateBase)validationContext.ObjectInstance;
            if (addDto.EmployeeNo == addDto.FistName)
            {
                return new ValidationResult(ErrorMessage, new[] { nameof(EmployeeAddorUpdateBase) });
            }
            return ValidationResult.Success;
        }
    }
}
